/*
* Copyright (c) 2007 by Kirill Kolodyazhniy.
* See the file "license.terms" for information on usage and redistribution.
*/

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include "log.h"

namespace Engine
{
	/**********************************************************************************************************/
	template<> Log* Singleton<Log>::m_singleton = 0;
	/**********************************************************************************************************/
	Log::Log()
	{
		Lock lock;
		char* buffer = 0;
		struct tm* newtime;
		time_t aclock;

		time( &aclock );
		newtime = localtime(&aclock );

		// convert local time to string.
		buffer = asctime(newtime);
		m_timestr = buffer;
	}
	/**********************************************************************************************************/
	void Log::WriteToFile(const std::string& fileName)const
	{
		Lock lock;
		if(!m_buffer.str().empty())
		{
			std::ofstream logFile(fileName.c_str(),std::ios_base::out);
			if(logFile)
			{
				logFile << m_timestr << std::endl;
				logFile << m_buffer.str();
				logFile << std::endl;
			}
		}
	}
	/**********************************************************************************************************/
}
